const path = require('path')

// vue.config.js
module.exports = {
  // 是否开启source map
  productionSourceMap: false,
  // 开发环境端口代理（http-proxy-middleware）
  devServer: {
    open: true, // 自动在浏览器中打开
    port: 8999, // 端口号
    proxy: {
      '/api': {
        target: 'http://106.13.1.45:8089',
        // ws: true,
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      }
    }
  },

  css: {
    extract: false // 不构建单独的css文件(分开打包)
  },

  configureWebpack: {
    resolve: { // 引用快捷路径
      extensions: ['.js', '.vue', '.json'],
      alias: {
        'vue$': 'vue/dist/vue.esm.js',
        '@': resolve('src'),
        '@base': resolve('src/components/base'),
        '@api': resolve('src/api'),
        '@mixin': resolve('src/assets/js/mixin'),
        '@js': resolve('src/assets/js'),
        '@images': resolve('src/assets/images'),
        '@stylus': resolve('src/assets/stylus'),
        '@views': resolve('src/views')
      }
    },
    externals: { // 加载 CDN 路径包
      'vue': 'Vue',
      'vue-router': 'VueRouter',
      'vuex': 'Vuex',
      'axios': 'axios',
      'element-ui': 'ELEMENT'
    }
  },

  /* 全局样式 变量 配置 vue add style-resources-loader */
  pluginOptions: {
    'style-resources-loader': {
      preProcessor: 'stylus',
      patterns: [resolve('src/assets/stylus/common.styl')] // 若引入所有 (必须src开头) ...stylus/*.styl
    }
  }
}

function resolve (dir) {
  return path.join(__dirname, dir)
}
